﻿using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;

namespace Basmus.Values.Web
{
    public class NameStringValuesCollectionValuesProvider : IValuesProvider<string>
    {
        private readonly NameValueCollection _nameValueCollection;

        public NameStringValuesCollectionValuesProvider(NameValueCollection nameValueCollection)
        {
            _nameValueCollection = nameValueCollection;
        }

        public IEnumerable<string> GetNames()
        {
            var names = _nameValueCollection.Keys.Cast<string>();
            return names;
        }

        public IEnumerable<string> GetValues(string name)
        {
            var hasValue = _nameValueCollection.AllKeys.Contains(name);
            if (hasValue)
            {
                var result = _nameValueCollection[name].Split(',');
                return result;
            }
            return null;
        }
    }
}